<?php  include VIEWPATH.'common/head.php';  ?>
    <script type="text/javascript">
        var status = '<?php echo $_GET['status'];?>';
        if(status == '-1'){
            alert('fail:<?php echo $_GET['msg'];?>');
        }
        function up_is_show(id){
            if(confirm("是否确认修改？")){
                var url = 'index.php?c=topic&m=up_is_show&id='+id;
                var param = {};
                common_ajax(url, param, function(data){
                    if(data.errorCode == 0) {
                        //表单提交
                        window.location.href = window.location.href;
                        return;
                    }else{
                        console.log(data.errorMsg);
                        alert(data.errorMsg);
                    }
                });
            }
        }
        function del_recommend(id){
            if(confirm("是否确认从推荐中删除此话题？")){
                var url = 'index.php?c=topic&m=del_recommend&id='+id;
                var param = {};
                common_ajax(url, param, function(data){
                    if(data.errorCode == 0) {
                        //表单提交
                        window.location.href = window.location.href;
                        return;
                    }else{
                        console.log(data.errorMsg);
                        alert(data.errorMsg);
                    }
                });
            }
        }
        //修改排序
        $(function () {
            $('.up_sort').blur(function () {
                var id=$(this).attr('data-id');
                var data_sort=$(this).attr('data-sort');
                var sort=$(this).val();
                var t=$(this);
                if(data_sort == sort){
                    return false;
                }
                if(sort == ''){
                    $(this).val(data_sort);
                    return false;
                }
                $.ajax({
                    type:'post',
                    url:"index.php?c=topic&m=up_sort",
                    data:{'id':id,'sort':sort},
                    dataType:'json',
                    success:function(result){
                        if(result['status'] == 1){
                            t.attr('data-sort',sort)
                        }else{
                            alert(result['msg'])
                        }
                    }
                });
            });
        })
        //修改排序
        function get_topic() {
            $.ajax({
                type:'post',
                url:"http://app.nuanguang.vip/api/topic/index/crontab_topic",
                data:{},
                dataType:'jsonp',
                jsonp: 'callback',
                success:function(result){
                        alert(result['msg'])
                }
            });
        }
    </script>
    <body class="gray-bg">
    <div class="wrapper wrapper-content ">
        <div class="add-btn" style="float:right;margin-bottom:5px;">
            <div class="modal fade" id="add_rules" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
                <div class="modal-dialog" style="width: 60%;"><div class="modal-content"></div></div>
            </div>
        </div>
        <div class="clearfix"></div>

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">

                        <div class="add-btn" style="float:right;margin-bottom:5px;">
                            <a href="index.php?c=topic&m=add_recommend" class="btn btn-danger" data-toggle="modal" data-target="#add_rules">添加话题</a>
                            <a href="javascript:void(0)" onclick="get_topic()" class="btn btn-danger" title="默认十分钟生成一次，如果着急前端展现，可点此按钮">生成</a>
                        </div>
                        <div class="clearfix"></div>
                        <div class="post_list">
                            <div class="table-data-list">
                                <form name="form" class="form" action="index.php?c=<?php echo $_REQUEST['c']; ?>&m=<?php echo $_REQUEST['m'];?>" method="post">
                                    <table class="table">
                                        <thead>
                                        <tr class="active">
                                            <th nowrap="nowrap">话题</th>
                                            <th nowrap="nowrap">排序</th>
                                            <th nowrap="nowrap">帖子数量</th>
                                            <th nowrap="nowrap">评论数量</th>
                                            <th nowrap="nowrap">播放数量</th>
                                            <th nowrap="nowrap">关注量</th>
                                            <th nowrap="nowrap">是否显示</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php foreach($list as $topic){
                                            ?>
                                            <tr>
                                                <td>
                                                    <a class="J_menuItem" data-names="话题规则"  href="index.php?c=post&m=post_list&&s_type_id=1&s_content=<?php echo $topic['id']?>">
                                                        <?php echo $topic['title'];?>
                                                    </a>
                                                </td>
                                                <td nowrap="nowrap">
                                                    <input type="text" placeholder="请输入排序" value="<?php echo $topic['sort'];?>" class="input-sm form-control col-sm-1 up_sort" style="width: 60px;" data-id="<?php echo $topic['id']?>" data-sort="<?php echo $topic['sort'];?>" maxlength="2" />


                                                </td>
                                                <td nowrap="nowrap"><?php echo $topic['post_num'];?></td>
                                                <td nowrap="nowrap"><?php echo $topic['reply_num'];?></td>
                                                <td nowrap="nowrap"><?php echo intval($topic['play_num']);?></td>
                                                <td nowrap="nowrap"><?php echo $topic['follow_user_num'];?></td>
                                                <td nowrap="nowrap">
                                                    <a href="javascript:void(0)" onclick="up_is_show(<?php echo $topic['id'];?>)"><?php echo $topic['is_show']==1?'显示':"隐藏";?>中</a>
                                                </td>

                                                <td nowrap="nowrap">
                                                    <a class="J_menuItem" data-names="话题规则"  href="index.php?c=topic&m=recommend&&id=<?php echo $topic['id']?>">编辑规则</a>
                                                    <a href="javascript:void(0)" onclick="del_recommend(<?php echo $topic['id'];?>)">删除</a>
                                                </td>
                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </form>
                            </div>
                            <div class="set_page">
                                <?php echo $multipage; ?>
                                <div class="clearfix"></div>
                            </div>

                        </div>

                    </div>
                </div>
            </div>

        </div>


    </div>
    <script src="http://gosspublic.alicdn.com/aliyun-oss-sdk-4.4.4.min.js"></script>
<?php  include VIEWPATH.'common/footer.php';  ?>